package caiziyou.com.designpattern.principle.opc;
/**
 * 开闭原则
 * 如果需要新增加图形需要修改原来的代码，违反了opc原则
 * @author Administrator
 *
 */
public class OcpDemo {

	public static void main(String[] args) {
		GraphicEditer graphicEditer = new GraphicEditer();
		graphicEditer.drawShape(new Rectangle());
		graphicEditer.drawShape(new Circle());
		graphicEditer.drawShape(new Triangle());
	}
}

class GraphicEditer {
	public void drawShape(Shape s) {
		if (s.my_type == 0) {
			drawRectangle(s);
		} else if (s.my_type == 1) {
			drawCircle(s);
		} else if (s.my_type == 2) {
			drawTriangle(s);
		}
	}

	public void drawRectangle(Shape s) {
		System.out.println("绘制矩形");
	}

	public void drawCircle(Shape s) {
		System.out.println("绘制圆形");
	}

	public void drawTriangle(Shape s) {
		System.out.println("绘制三角形");
	}
}

class Shape {
	int my_type;
}

class Circle extends Shape {
	Circle() {
		this.my_type = 1;
	}
}

class Rectangle extends Shape {
	Rectangle() {
		this.my_type = 0;
	}
}

class Triangle extends Shape {
	Triangle() {
		this.my_type = 2;
	}
}
